package com.jd.sunny.util;

public class BaseUtil {


    /**
     * 补全数字
     *
     * @param originalNumber 原始数据,先将数字转换成String，防止超出范围
     * @param length         不全后数字总长度
     * @param type           max 和min
     * @return
     * @throws Exception
     */
    public static String completeNumber(String originalNumber, long length, String type) throws Exception {
        String number = originalNumber;

        //判断数字长度
        if (length < String.valueOf(originalNumber).length()) {
            throw new Exception("对不起，原数字长度有误");
        } else if (type.equalsIgnoreCase("max")) {
            //补全最大
            while (number.length() < length) {
                number = number + "9";
            }
        } else if (type.equalsIgnoreCase("min")) {
            //补全最小
            while (number.length() < length) {
                number = number + "0";
            }
        }
        return number;
    }

}
